package com.huluobo.a2208kotlindouyindemo.login

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.Money
import com.huluobo.base.bean.UserBean
import com.huluobo.base.db.DouYinDatabase
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/12/25.
 */
@HiltViewModel
class LoginViewModel @Inject constructor(
    val apiService: ApiService,
    val db: DouYinDatabase
) : BaseViewModel() {
    val loginSuccess by lazy { MutableLiveData<UserBean>() }
    fun login(body: RequestBody) {
        executeNetwork(
            { apiService.login(body) },
            loginSuccess::postValue
        )
    }

    val insertMoneySuccess by lazy { MutableLiveData<String>() }
    fun insertMoney(money: Money) {
        executeDb(
            {
                db.getMoneyDao().insertMoney(money)
                "添加余额成功"
            },
            insertMoneySuccess::postValue
        )
    }
}